<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>The Index Page</h2>
<button onclick="doBuy()">购买</button>
<span id="result"></span>
<!--<script src="/js/axios.min.js"></script>-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    function doBuy() {
        //1.定义请求的url(注意对应的是网关地址)
        let url="http://localhost:9000/nacos/provider/echo/1";
        let span = document.getElementById("result");
        //2.基于axios框架发送ajax异步请求
        axios.get(url)
        .then(function (result) {
            console.log(result);
            if (!result.data.status) {
                span.innerHTML = result.data;
            }else {
                span.innerHTML = result.data.message;

            }
        })
            .catch(function(error){//服务端没有处理异常，走这里
            if(error.response.status==429){
                span.innerHTML=error.response.statusText;
            }
        });
    }
</script>
</body>
</html>